import Base from "./Base";
import EntityOption from "./EntityOption";
import FormRef from "./FormRef";

export default abstract class Form extends Base {
    abstract clear(): void
    private static _events = {}
    private static initOption: EntityOption = {
        labelWidth: 100,
        span: 8
    }
    private _opts?: EntityOption
    id?: string | number
    _id?: string | number

    constructor(opts?: EntityOption) {
        super();
        this.opts = { ...Form.initOption, ...opts }
    }

    get opts() {
        return this._opts
    }

    set opts(opts) {
        this._opts = opts
    }

    getRef(): FormRef {
        return {} as any
    }

    getLabel(key: string): string {
        return 'label of' + key
    }

    setForm(form: Form) {
        Object.assign(this, form)
    }

    getBindingValue<T>(_filter?: string[], _type?: 'include' | 'exclude'): T {
        return {} as T
    }

    submit(_call: (done: () => void) => void) { }

    protected emit(ev: string, ...val: any[]) {
        const evs = this.opts?.events as any;
        evs && evs[ev] && evs[ev](...val);
        if (Form._events[ev]) {
            Form._events[ev](...val)
        }
    }
}